

---------------------------Reyi-----------------------
require "girl/init"

local CB_gui = nil;
local title = "";
local submit = false;


function CB_gui_init()
	local ww,wh = g._getWidth(), g._getHeight();
	local cw,ch = 800,600;
	
	g:createCanvas("CB_canvas", cw, ch);
	iw, ih = g:getImageSize("normal");
	CB_gui = Girl.Gui(0, 0, cw, ch, g, "CB_canvas");
	
	
	----------背景-------------
	items = {"sb1","sb2","scb_item"};
	

	local background = Girl.View.Picture(cw, ch);
	
	background:setImage("normal");
	background:setImageColor({255,255,255,200});
	background:setMode(2,{x=4, y=4, width=12, height=12}, iw, ih);
	CB_gui:add("bg", background, 0, 0);

	---------------------角色---------------------------
	local avatar = Girl.View.Avatar (236,464,"xiaoyu");
	local charater = {"yu_1","yu_2","yu_3"};
	avatar:setCharater (charater);	
	background:add("char1",avatar,100,100);
	avatar:initTimer();
	-----------文本对话框-----------------------
	local gameMessageBox = Girl.View.GameMessageBox (800,100);
	background:add("gameMessageBox",gameMessageBox,0,500);
	gameMessageBox:setBackground("normal");
	gameMessageBox:setMode(2,{x=4, y=4, width=12, height=12}, 300, 100);
	gameMessageBox:setFont("simhei", 18);	
	local fn = "textFile.txt";
	local luafile = io.open(fn,"r");
	local text = {};
	local temp = luafile:read("*line");
	while temp do 
		table.insert(text, temp);
		temp = luafile:read("*line");
	end
	luafile:close();
	
	gameMessageBox.endReading = function (this)
		--print ("endReading");
		--this.parent:get("char1"):setCurrentPic(2);
	end
	
	gameMessageBox.startReading = function (this)
		
	end
	
	
	gameMessageBox.onMouseClick = function (this)
		--	this.parent:get("char1"):setCurrentPic(3);
		--this.parent:get("char1"):startMoveTo(600,50,60);
		this.parent:get("char1"):startShack(20);
	end	
	
	gameMessageBox.onKeyPress = function (this)
		this.parent:get("char1"):stopMove();
	end
	
	gameMessageBox:setLineLength(25);
	gameMessageBox:setText(text);

	gameMessageBox:setTimer();
	

	-------------checkBox Item ---------------
	--[[for i =1,table.getn(items) do
	local checkbox = Girl.View.CheckBox (100,20); 
		background:add("checkbox"..i, checkbox, 0,40*i);
		checkbox:setStateImage("unselected","selected","partselcted");
		checkbox:setLabel(items[i],"font10");
		checkbox:setStateColor({255,255,255,255},{200,200,200,150},{255,255,255,255});
		checkbox:setLabelColor({255,255,255,255},{200,200,200,150},{255,255,255,255});
		
		checkbox.onButtonClick = function (this)
			if(checkbox.state == 1) then 
			print(checkbox.label);
			end
		end 
	end
	
	-----------------checkBox Button----------
	local b1 = Girl.View.Button(60,20);
	b1:setFont("font10");
	b1:setImage("normal", "normal", "click");
	b1:setLabel("OK",20,5);
	b1:setImageColor({100,200,255,200},{150,250,255,200},{150,250,255,200});
	b1:setMode(2,{x=4, y=4, width=12, height=12}, iw, ih);
	b1.onButtonClick = function (this)

	end
	
	background:add(nil,b1,80,180);
	
	local b2 = Girl.View.Button(60,20);
	b2:setFont("font10");
	b2:setImage("normal", "normal", "click");
	b2:setLabel("Cancel",20,5);
	b2:setImageColor({100,200,255,200},{150,250,255,200},{150,250,255,200});
	b2:setMode(2,{x=4, y=4, width=12, height=12}, iw, ih);
	b2.onButtonClick = function (this)
		
	end
	
	background:add(nil,b2,160,180);]]--
end



function love.load()
	math.randomseed(os.time());
	g = Girl.Graphics();
	g:createImageFromPath("normal","img/normal.png");
	g:createImageFromPath("click","img/click.png");
	g:createImageFromPath("yu_1","img/yu_1.png");
	g:createImageFromPath("yu_2","img/yu_2.png");
	g:createImageFromPath("yu_3","img/yu_3.png");
	g:createFontFromSize("font8",8);
	g:createFontFromSize("font10",10);
	g:createFontFromPath("simhei","simhei.ttf",12);   -------------------
	g._setBackgroundColor({0,0,0});
	
	
	g:createImageFromPath("unselected", "img/unselected.png");   
	g:createImageFromPath("selected", "img/selected.png");   
	g:createImageFromPath("partselcted", "img/partselcted.png");   
	
	CB_gui_init();
end

function love.update(dt)

	CB_gui:update(dt);

end

function love.draw()
	CB_gui:draw();

end

function love.mousepressed(x, y, button)
	CB_gui:mousepressed(x, y, button) 

end

function love.mousereleased(x, y, button)
	CB_gui:mousereleased(x, y, button);

end

function love.keypressed(key, unicode)
	CB_gui:keypressed(key, unicode);
end

function love.keyreleased(key)
	CB_gui:keyreleased(key);
end
